﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Monocle.DataModel;
using Monocle.DataModel.CustomDTO;

namespace Monocle.DataProvider
{
    public interface IDataProvider
    {
        void LogException(Exception e, String method);

        #region App
        /// <summary>
        /// Gets a specific App from the database by its unique ID
        /// </summary>
        /// <param name="ID">Unique identifier</param>
        /// <returns>App DTO</returns>
        tApp GetApp(Guid ID);

        /// <summary>
        /// Get all Apps in the DB
        /// </summary>
        /// <returns></returns>
        List<tApp> GetApps();

        /// <summary>
        /// Save a App to the database. Used for both updating and creating new entities
        /// </summary>
        /// <param name="dto">DTO to save</param>
        /// <returns>Saved DTO</returns>
        tApp SaveApp(tApp dto);
        #endregion

        #region Page
        /// <summary>
        /// Get all pages associated with an app
        /// </summary>
        /// <param name="AppID">ID of the App</param>
        /// <returns>List of DTOes</returns>
        List<tPage> GetPagesByApp(Guid AppID);

        /// <summary>
        /// Gets a page by ID. 
        /// </summary>
        /// <param name="pageID">The primary key of the page</param>
        /// <returns>The App corresponding to the id</returns>
        tPage GetPage(Guid pageID);

        /// <summary>
        /// Save a page to the database. Used for both updating and creating new entities
        /// </summary>
        /// <param name="dto">DTO to save</param>
        /// <returns>Saved DTO</returns>
        tPage SavePage(tPage dto);

        /// <summary>
        /// Deletes a page from the database
        /// </summary>
        /// <param name="dto">DTO to delete</param>
        void DeletePage(tPage dto);
        #endregion

        #region PageItem
        /// <summary>
        /// Get all items associated with a page
        /// </summary>
        /// <param name="pageID">ID of the page</param>
        /// <returns>List of DTOes</returns>
        List<tPageItem> GetPageItemsByPage(Guid pageID);

        /// <summary>
        /// Gets a pageitem by ID. 
        /// </summary>
        /// <param name="pageID">The primary key of the pageitem</param>
        /// <returns>The App corresponding to the id</returns>
        tPageItem GetPageItem(Guid pageID);

        /// <summary>
        /// Save a page to the database. Used for both updating and creating new entities
        /// </summary>
        /// <param name="dto">DTO to save</param>
        /// <returns>Saved DTO</returns>
        tPageItem SavePageItem(tPageItem dto);

        /// <summary>
        /// Deletes a pageitem from the database
        /// </summary>
        /// <param name="dto">DTO to delete</param>
        void DeletePageItem(tPageItem dto);

        /// <summary>
        /// Get a custom DTO containing the PageItem plus the module(s) attached to it
        /// </summary>
        /// <param name="pageItemID">Guid of the pageItem</param>
        /// <returns>PageItem DTO with Modules</returns>
        PageItemWithModuleDTO GetPageItemWithModule(Guid pageItemID);

        /// <summary>
        /// Get a list of custom DTO containing the PageItem plus the module(s) attached to it
        /// </summary>
        /// <param name="pageID">Guid of the page</param>
        /// <returns>PageItem DTO with Modules</returns>
        List<PageItemWithModuleDTO> GetPageItemsWithModule(Guid pageID);
        #endregion

        #region user

        /// <summary>
        /// Gets a user by his email
        /// </summary>
        /// <param name="email"></param>
        /// <returns>tUser</returns>
        tUser GetUserByEmail(String email);

        /// <summary>
        /// Get the role of a given user
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        List<tUserRole> GetUsersRoles(tUser user);

        /// <summary>
        /// Get the role of all userroles
        /// </summary>
        /// <returns></returns>
        List<tUserRole> GetUserRoles();

        /// <summary>
        /// Create a new user in the database with a freshly generated random password
        /// </summary>
        /// <param name="dto">DTO of user to create</param>
        /// <returns>User DTO with plaintext password</returns>
        tUser CreateUser(tUser dto);

        /// <summary>
        /// Saves a changed user in the database
        /// </summary>
        /// <param name="user">User to be saved</param>
        /// <returns>Saved and updated user</returns>
        tUser SaveUser(tUser user);

        /// <summary>
        /// Gets all users
        /// </summary>
        /// <returns></returns>
        List<tUser> GetUsers();

        /// <summary>
        /// Gets a user by ID
        /// </summary>
        /// <param name="id"></param>
        /// <returns>Password stripped tUser</returns>
        tUser GetUser(Guid id);

        /// <summary>
        /// Delete user
        /// </summary>
        /// <param name="dto"></param>
        void DeleteUser(tUser dto);

        /// <summary>
        /// Set (and overwrite) the users current roles
        /// </summary>
        /// <param name="user"></param>
        /// <param name="roles"></param>
        bool SetUserRoles(tUser user, List<Guid> roles);

        #endregion

        #region Module HTML
        /// <summary>
        /// Gets a pageitem by ID. 
        /// </summary>
        /// <param name="moduleID">The primary key of the module</param>
        /// <returns>The HTML ModuleDTO</returns>
        tHTML GetHTMLModule(Guid moduleID);

        /// <summary>
        /// Save a page to the database. Used for both updating and creating new entities
        /// </summary>
        /// <param name="dto">DTO to save</param>
        /// <returns>Saved DTO</returns>
        tHTML SaveHTMLModule(tHTML dto);

        #endregion

        #region Module HTML
        /// <summary>
        /// Gets a FacebookModule by ID. 
        /// </summary>
        /// <param name="moduleID">The primary key of the module</param>
        /// <returns>The HTML ModuleDTO</returns>
        tFacebook GetFacebookModule(Guid moduleID);

        /// <summary>
        /// Save a page to the database. Used for both updating and creating new entities
        /// </summary>
        /// <param name="dto">DTO to save</param>
        /// <returns>Saved DTO</returns>
        tFacebook SaveFacebookModule(tFacebook dto);

        #endregion
        bool Ping();
    }
}
